﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Theme_Index_jyzx : System.Web.UI.Page
{
    PowerCreator.LMS.Web.CMS.NewType opNewsType = new PowerCreator.LMS.Web.CMS.NewType();
    PowerCreator.LMS.Web.CMS.New opNews = new PowerCreator.LMS.Web.CMS.New();
    protected PowerCreator.LMS.Web.Config.WebConfig config = new PowerCreator.LMS.Web.Config.WebConfig();
    private int iPageSize = 12;
    private string typeid = "0";
    public string search = "";
    private string type = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = "教育资讯";
        if (!IsPostBack)
        {
            //BinderNews_GZ();
            //BinderNews_CZ();
            //BinderNews_XX();
            //BinderNews_XQ();
            BinderNewsType();
            BinderNewsTypelist();
            //BinderNews_GN();
            //BinderNews_BS();
            //else if (Request.QueryString["typeid"] != null)
            //{
            //    typeid = Request.QueryString["typeid"];
            //    PowerCreator.LMS.CMS.Entity.VOTNewType vo = new PowerCreator.LMS.CMS.Entity.VOTNewType();
            //    vo = opNewsType.Load(int.Parse(typeid));
            //    type = vo.NewTypeName;
            //}

            //if (type == "jyzx")
            //    type = "教育资讯";
            //else if (type == "jyzt")
            //    type = "教育专题";
            //else if (type == "szyw")
            //    type = "时政要闻";
            //else if (type == "tzgg")
            //    type = "通知公告";
            //ViewState["type"] = type;
            //this.Title = type;
            //lbl_typeName.Text = type;
            //search = GetSearch(type);
            //BinderPager(search);
            //BinderNews(search, 1);
        }
    }

    private void BinderNewsType()
    {
        string search = string.Format(" IsTop={0} and IsShow={1} ", "1", "1");
        string orderby = "";
        int int_count = opNewsType.Count(search);
        DataTable dt1 = opNewsType.Query(search,int_count, 1);
        //for (int j = 0; j < dt1.Rows.Count; j++)
        //{
        //    if (dt1.Rows[j]["NewUrl"] == null)
        //        dt1.Rows[j]["NewUrl"] = "OpenNews.aspx?NewsID=" + dt1.Rows[j]["NewID"].ToString();
        //    else if (dt1.Rows[j]["NewUrl"].ToString().Length == 0)
        //        dt1.Rows[j]["NewUrl"] = "OpenNews.aspx?NewsID=" + dt1.Rows[j]["NewID"].ToString();
        //}
        rpt_NewsType.DataSource = dt1;
        rpt_NewsType.DataBind();
        for (int i = 0; i < rpt_NewsType.Items.Count; i++)
        {
            Label lbl_newtypeid = (Label)rpt_NewsType.Items[i].FindControl("lbl_NewsTypeID");
            Repeater rpt_new = (Repeater)rpt_NewsType.Items[i].FindControl("rpt_news_gz");
            BinderNews_GZ(lbl_newtypeid.Text, rpt_new,5);
        }
    }

    private void BinderNewsTypelist()
    {
        string search = string.Format(" IsTop={0} and IsShow={1} ", "0", "1");
        string orderby = "";
        int int_count = opNewsType.Count(search);
        DataTable dt1 = opNewsType.Query(search, int_count, 1);
        rpt_newsTypelist.DataSource = dt1;
        rpt_newsTypelist.DataBind();

        for (int i = 0; i < rpt_newsTypelist.Items.Count; i++)
        {
            Label lbl_newtypeid = (Label)rpt_newsTypelist.Items[i].FindControl("lbl_NewsTypelistID");
            Repeater rpt_new = (Repeater)rpt_newsTypelist.Items[i].FindControl("rpt_news_gn");
            BinderNews_GZ(lbl_newtypeid.Text, rpt_new,10);
        }
    }

    private void BinderNews_GZ(string str_newtypeid,Repeater rpt,int pagesize)
    {
        string search = string.Format(" FKNewNewTypeID={0} and NewState=1", str_newtypeid);
        string orderby = "NewIsTop desc, NewPublishTime desc ";
        DataTable dt1 = opNews.Query(search, orderby, pagesize, 1);
        for (int j = 0; j < dt1.Rows.Count; j++)
        {
            if (dt1.Rows[j]["NewUrl"] == null)
                dt1.Rows[j]["NewUrl"] = "OpenNews.aspx?NewsID=" + dt1.Rows[j]["NewID"].ToString();
            else if (dt1.Rows[j]["NewUrl"].ToString().Length == 0)
                dt1.Rows[j]["NewUrl"] = "OpenNews.aspx?NewsID=" + dt1.Rows[j]["NewID"].ToString();

            dt1.Rows[j]["NewPublishTime"] = DateTime.Parse(dt1.Rows[j]["NewPublishTime"].ToString()).ToString("MM-dd");
        }
        rpt.DataSource = dt1;
        rpt.DataBind();
    }
}
